//
//  AppManager.m
//  PushInappTestiOS
//
//  Created by KyuJin on 12. 12. 30..
//
//

#import "AppManager.h"
#import "JSON.h"

static AppManager* _instance;
@implementation AppManager

- (void) dealloc
{
    [_instance release];
    _instance = nil;
    
    [super dealloc];
}
+ (AppManager*) getInstance
{
    if(!_instance)
    {
        _instance = [[self alloc] init];
    }
    
    return _instance;
}

- (void) showAlertDialog:(NSString*)title with:(NSString*)message
{
    NSLog(@"%@", message);
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:@"확인" otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
}

- (void) sendJavascript:(NSString*)callback data:(NSDictionary*)data
{
    NSLog(@"%s", __FUNCTION__);
    @try {
        SBJsonWriter *jsonWriter = [[SBJsonWriter alloc] init];
        NSString *jsonString = [jsonWriter stringWithObject:data];
        
        [self.webview stringByEvaluatingJavaScriptFromString:
         [NSString stringWithFormat:@"%@(%@);", callback, jsonString]];
        
        [jsonWriter release];
    }
    @catch (NSException *exception) {
        [self showAlertDialog:@"Exception SendJavascript" with:[exception reason]];
    }
    @finally {
        
    }
}
@end
